package com.example.xiaohei.ui.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import androidx.lifecycle.ViewModelProvider
import com.example.xiaohei.R
import com.example.xiaohei.databinding.FragmentRecommendBinding
import com.example.xiaohei.viewmodel.ReCommendViewModel

class AccountFragment : Fragment() , LifecycleObserver ,View.OnClickListener{
    lateinit var binding: FragmentRecommendBinding

    val viewModel by lazy {
        ViewModelProvider(this, ViewModelProvider.AndroidViewModelFactory(requireActivity().application)).get(
            ReCommendViewModel::class.java)
    }
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_recommend,container,false)
        initData()
        return binding.root
    }

    private fun initData(){
        binding?.run {
            btTest.text = "点击我试一试"
            tvTest.text = "111"
        }
    }


    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    fun myOnStar() {
        print("onStar")
    }

    override fun onClick(v: View?) {
        v?.let {
            when(it.id){
                R.id.bt_test->{
                    binding.tvTest.text = "惊喜不惊喜，意外不意外"
                }
            }
        }

    }
}